package com.ruoyi.service.jpjs.capital.impl;

import com.ruoyi.mapper.jpjs.capital.CapitalMapper;
import com.ruoyi.service.jpjs.capital.CapitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @author zeo
 * @explain 劳资填报业务层
 * @date 2021/4/9 13:42
 */
@Service
public class CapitalServiceImpl implements CapitalService {

    @Autowired
    CapitalMapper capitalMapper;

    @Override
    public List<Map> selectProList(Map map) {
        return capitalMapper.selectProList(map);
    }

    @Override
    public int proAdd(Map map) {
        String UUID = getUUID();
        map.put("UUID", UUID);
        return capitalMapper.proAdd(map) + capitalMapper.proAddTypeByProId(UUID);
    }

    @Override
    public int workAdd(Map map) {
        return capitalMapper.workAdd(map);
    }

    @Override
    public int positionAdd(Map map) {
        return capitalMapper.positionAdd(map);
    }

    public static String getUUID() {
        return UUID.randomUUID().toString().replace("-", "").toUpperCase();
    }

    @Override
    public int remove(String id) {
        //判断是否是工种
        if (capitalMapper.selectIsWorkCount(id) == 0) {
            //删除施工部位及数
            return capitalMapper.deleteData("position_id", id) + capitalMapper.deleteWordOrPosition("capital_position", id);
        } else {
            //删除工种及数据
            return capitalMapper.deleteData("work_id", id) + capitalMapper.deleteWordOrPosition("capital_work", id);
        }
    }
}
